package com.ssy.lingxi.purchase.controller.tender;

import cn.hutool.core.bean.BeanUtil;
import com.ssy.lingxi.common.controller.BaseController;
import com.ssy.lingxi.common.exception.BusinessException;
import com.ssy.lingxi.common.model.dto.UserLoginCacheDTO;
import com.ssy.lingxi.common.response.PageData;
import com.ssy.lingxi.common.response.ResponseCode;
import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.purchase.api.dto.request.tender.*;
import com.ssy.lingxi.purchase.api.dto.response.tender.InviteTenderMemberResponse;
import com.ssy.lingxi.purchase.api.dto.response.tender.InviteTenderResponse;
import com.ssy.lingxi.purchase.api.dto.response.tender.SubmitTenderInviteTenderMemberDetailResponse;
import com.ssy.lingxi.purchase.api.dto.response.tender.TenderStatusResponse;
import com.ssy.lingxi.purchase.api.enums.tender.SubmitTenderInStatusEnum;
import com.ssy.lingxi.purchase.api.enums.tender.SubmitTenderOutStatusEnum;
import com.ssy.lingxi.purchase.entity.tender.InviteTender;
import com.ssy.lingxi.purchase.entity.tender.InviteTenderMember;
import com.ssy.lingxi.purchase.entity.tender.SubmitTender;
import com.ssy.lingxi.purchase.entity.tender.SubmitTenderMateriel;
import com.ssy.lingxi.purchase.service.tender.ISubmitTenderService;
import com.ssy.lingxi.search.api.model.request.SimpleIdListRequest;
import com.ssy.lingxi.workflow.api.model.vo.response.ComplexTaskDefVO;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @menu: 招投标-投标管理
 * 投标管理类
 * @author jw.chen
 * @version 2.0.0
 * @date 2021/3/1
 */
@RestController
@RequestMapping("/purchase/submitTender")
public class SubmitTenderController extends BaseController {

    @Resource
    private ISubmitTenderService submitTenderService;

    /**
     * 投标-招标查询列表
     */
    @RequestMapping(value = "/getInviteTenderList", method = RequestMethod.POST)
    public Wrapper<PageData<InviteTenderResponse>> getInviteTenderList(@RequestBody InviteTenderQueryRequest inviteTenderQueryRequest) {
        UserLoginCacheDTO sysUser = this.getSysUser();
        Page<InviteTenderMember> result = submitTenderService.getInviteTenderList(sysUser, inviteTenderQueryRequest);
        List<InviteTenderMember> inviteTenderMemberList = result.getContent();
        if(inviteTenderMemberList.size() > 0){
            List<InviteTenderResponse> resultList = inviteTenderMemberList.stream().map(inviteTenderMember -> {
                InviteTender inviteTender = inviteTenderMember.getInviteTender();
                InviteTenderResponse inviteTenderResponse = BeanUtil.copyProperties(inviteTender, InviteTenderResponse.class);
                inviteTenderResponse.setSubmitTenderOutStatusValue(SubmitTenderOutStatusEnum.getMessage(inviteTenderMember.getSubmitTenderOutStatus()));
                inviteTenderResponse.setSubmitTenderInStatusValue(SubmitTenderInStatusEnum.getMessage(inviteTenderMember.getSubmitTenderInStatus()));
                return inviteTenderResponse;
            }).collect(Collectors.toList());
            return Wrapper.success(new PageData<>(result.getTotalElements(), resultList));
        }else{
            return Wrapper.success(new PageData<>(result.getTotalElements(), new ArrayList<>()));
        }
    }

    /**
     * 投标-招标查询-外部状态
     */
    @RequestMapping(value = "/getInviteTenderOutStatus", method = RequestMethod.GET)
    public Wrapper<List<TenderStatusResponse>> getInviteTenderOutStatus() {
        SubmitTenderOutStatusEnum[] values = SubmitTenderOutStatusEnum.values();
        List<TenderStatusResponse> list = new ArrayList<>();
        for (SubmitTenderOutStatusEnum submitTenderOutStatus : values) {
            Integer code = submitTenderOutStatus.getCode();
            String message = submitTenderOutStatus.getMessage();
            TenderStatusResponse tenderStatusResponse = new TenderStatusResponse();
            tenderStatusResponse.setCode(code);
            tenderStatusResponse.setMessage(message);
            list.add(tenderStatusResponse);
        }
        return Wrapper.success(list);
    }

    /**
     * 投标-招标查询-内部状态
     */
    @RequestMapping(value = "/getInviteTenderInStatus", method = RequestMethod.GET)
    public Wrapper<List<TenderStatusResponse>> getInviteTenderInStatus() {
        SubmitTenderInStatusEnum[] values = SubmitTenderInStatusEnum.values();
        List<TenderStatusResponse> list = new ArrayList<>();
        for (SubmitTenderInStatusEnum submitTenderInStatusEnum : values) {
            Integer code = submitTenderInStatusEnum.getCode();
            String message = submitTenderInStatusEnum.getMessage();
            TenderStatusResponse tenderStatusResponse = new TenderStatusResponse();
            tenderStatusResponse.setCode(code);
            tenderStatusResponse.setMessage(message);
            list.add(tenderStatusResponse);
        }
        return Wrapper.success(list);
    }

    /**
     * 查询招标信息
     * @param inviteTenderId 招标id
     */
    @RequestMapping(value = "/getInviteTender", method = RequestMethod.GET)
    public Wrapper<SubmitTenderInviteTenderMemberDetailResponse> getInviteTender(@RequestParam Long inviteTenderId) {
        UserLoginCacheDTO sysUser = this.getSysUser();
        InviteTenderMember inviteTenderMember = submitTenderService.getInviteTenderMember(sysUser, inviteTenderId);
        if(inviteTenderMember != null){
            SubmitTenderInviteTenderMemberDetailResponse submitTenderResponse = BeanUtil.copyProperties(inviteTenderMember, SubmitTenderInviteTenderMemberDetailResponse.class);
            submitTenderResponse.setSubmitTenderInStatusValue(SubmitTenderInStatusEnum.getMessage(inviteTenderMember.getSubmitTenderInStatus()));
            submitTenderResponse.setSubmitTenderOutStatusValue(SubmitTenderOutStatusEnum.getMessage(inviteTenderMember.getSubmitTenderOutStatus()));
            return Wrapper.success(submitTenderResponse);
        }else{
            throw new BusinessException(ResponseCode.PURCHASE_INVITE_TENDER_NOT_EXIST);
        }
    }

    /**
     * 投标-投标查询列表
     */
    @RequestMapping(value = "/getSubmitTenderList", method = RequestMethod.POST)
    public Wrapper<PageData<InviteTenderMemberResponse>> getSubmitTenderList(@RequestBody SubmitTenderQueryRequest submitTenderQueryRequest) {
        UserLoginCacheDTO sysUser = this.getSysUser();
        submitTenderQueryRequest.setIsSelectSubmit(true);
        Page<InviteTenderMember> result = submitTenderService.getSubmitTenderList(sysUser, submitTenderQueryRequest);
        List<InviteTenderMember> inviteTenderMemberList = result.getContent();
        List<InviteTenderMemberResponse> resultList = inviteTenderMemberList.stream().map(inviteTenderMember -> {
            Integer submitTenderInStatus = inviteTenderMember.getSubmitTenderInStatus();
            Integer submitTenderOutStatus = inviteTenderMember.getSubmitTenderOutStatus();
            InviteTenderMemberResponse inviteTenderMemberResponse = BeanUtil.copyProperties(inviteTenderMember, InviteTenderMemberResponse.class);
            inviteTenderMemberResponse.setSubmitTenderInStatusValue(SubmitTenderInStatusEnum.getMessage(submitTenderInStatus));
            inviteTenderMemberResponse.setSubmitTenderOutStatusValue(SubmitTenderOutStatusEnum.getMessage(submitTenderOutStatus));
            if(submitTenderOutStatus.intValue() == SubmitTenderOutStatusEnum.Not_Finish_Notice.getCode().intValue() && submitTenderInStatus.intValue() == SubmitTenderInStatusEnum.Submitted_Invite_Tender_Register.getCode()){
                inviteTenderMemberResponse.setIsSubmitTenderUpdate(true);
            }
            return inviteTenderMemberResponse;
        }).collect(Collectors.toList());
        return Wrapper.success(new PageData<>(result.getTotalElements(), resultList));
    }

    /**
     * 投标-投标查询-外部状态
     */
    @RequestMapping(value = "/getSubmitTenderOutStatus", method = RequestMethod.GET)
    public Wrapper<List<TenderStatusResponse>> getSubmitTenderOutStatus() {
        SubmitTenderOutStatusEnum[] values = SubmitTenderOutStatusEnum.values();
        List<TenderStatusResponse> list = new ArrayList<>();
        for (SubmitTenderOutStatusEnum submitTenderOutStatus : values) {
            Integer code = submitTenderOutStatus.getCode();
            if(code >= SubmitTenderOutStatusEnum.Not_Submit_Tender.getCode()){
                String message = submitTenderOutStatus.getMessage();
                TenderStatusResponse tenderStatusResponse = new TenderStatusResponse();
                tenderStatusResponse.setCode(code);
                tenderStatusResponse.setMessage(message);
                list.add(tenderStatusResponse);
            }
        }
        return Wrapper.success(list);
    }

    /**
     * 投标-投标查询-内部状态
     */
    @RequestMapping(value = "/getSubmitTenderInStatus", method = RequestMethod.GET)
    public Wrapper<List<TenderStatusResponse>> getSubmitTenderInStatus() {
        SubmitTenderInStatusEnum[] values = SubmitTenderInStatusEnum.values();
        List<TenderStatusResponse> list = new ArrayList<>();
        for (SubmitTenderInStatusEnum submitTenderInStatusEnum : values) {
            Integer code = submitTenderInStatusEnum.getCode();
            if(code >= SubmitTenderInStatusEnum.Not_Save_Submit_Tender.getCode()){
                String message = submitTenderInStatusEnum.getMessage();
                TenderStatusResponse tenderStatusResponse = new TenderStatusResponse();
                tenderStatusResponse.setCode(code);
                tenderStatusResponse.setMessage(message);
                list.add(tenderStatusResponse);
            }
        }
        return Wrapper.success(list);
    }

    /**
     * 投标-待招标报名列表
     */
    @RequestMapping(value = "/getSubmitTenderRegisterList", method = RequestMethod.POST)
    public Wrapper<PageData<InviteTenderMemberResponse>> getSubmitTenderRegisterList(@RequestBody SubmitTenderQueryRequest submitTenderQueryRequest) {
        UserLoginCacheDTO sysUser = this.getSysUser();

        List<Integer> submitTenderOutStatusList = new ArrayList<>();
        submitTenderOutStatusList.add(SubmitTenderOutStatusEnum.Not_Invite_Tender_Register.getCode());
        submitTenderOutStatusList.add(SubmitTenderOutStatusEnum.Register_Check_Not_Pass.getCode());
        submitTenderQueryRequest.setSubmitTenderOutStatusList(submitTenderOutStatusList);

        Page<InviteTenderMember> result = submitTenderService.getSubmitTenderList(sysUser, submitTenderQueryRequest);
        List<InviteTenderMember> inviteTenderMemberList = result.getContent();
        List<InviteTenderMemberResponse> resultList = inviteTenderMemberList.stream().map(inviteTenderMember -> {
            Integer submitTenderInStatus = inviteTenderMember.getSubmitTenderInStatus();
            Integer submitTenderOutStatus = inviteTenderMember.getSubmitTenderOutStatus();
            InviteTenderMemberResponse inviteTenderMemberResponse = BeanUtil.copyProperties(inviteTenderMember, InviteTenderMemberResponse.class);
            inviteTenderMemberResponse.setSubmitTenderInStatusValue(SubmitTenderInStatusEnum.getMessage(submitTenderInStatus));
            inviteTenderMemberResponse.setSubmitTenderOutStatusValue(SubmitTenderOutStatusEnum.getMessage(submitTenderOutStatus));
            if(submitTenderInStatus.intValue() == SubmitTenderInStatusEnum.Not_Submitted_Invite_Tender_Register.getCode().intValue()){
                inviteTenderMemberResponse.setIsRegister(true);
            }else{
                inviteTenderMemberResponse.setIsReRegister(true);
            }
            return inviteTenderMemberResponse;
        }).collect(Collectors.toList());
        return Wrapper.success(new PageData<>(result.getTotalElements(), resultList));
    }

    /**
     * 投标-待提交资格预审列表
     */
    @RequestMapping(value = "/getSubmitTenderQualificationsList", method = RequestMethod.POST)
    public Wrapper<PageData<InviteTenderMemberResponse>> getSubmitTenderQualificationsList(@RequestBody SubmitTenderQueryRequest submitTenderQueryRequest) {
        UserLoginCacheDTO sysUser = this.getSysUser();

        List<Integer> submitTenderOutStatusList = new ArrayList<>();
        submitTenderOutStatusList.add(SubmitTenderOutStatusEnum.Not_Submitted_Qualifications_Check.getCode());
        submitTenderOutStatusList.add(SubmitTenderOutStatusEnum.Qualifications_Check_Not_Pass.getCode());
        submitTenderQueryRequest.setSubmitTenderOutStatusList(submitTenderOutStatusList);

        Page<InviteTenderMember> result = submitTenderService.getSubmitTenderList(sysUser, submitTenderQueryRequest);
        List<InviteTenderMember> inviteTenderMemberList = result.getContent();
        List<InviteTenderMemberResponse> resultList = inviteTenderMemberList.stream().map(inviteTenderMember -> {
            Integer submitTenderInStatus = inviteTenderMember.getSubmitTenderInStatus();
            Integer submitTenderOutStatus = inviteTenderMember.getSubmitTenderOutStatus();
            InviteTenderMemberResponse inviteTenderMemberResponse = BeanUtil.copyProperties(inviteTenderMember, InviteTenderMemberResponse.class);
            inviteTenderMemberResponse.setSubmitTenderInStatusValue(SubmitTenderInStatusEnum.getMessage(submitTenderInStatus));
            inviteTenderMemberResponse.setSubmitTenderOutStatusValue(SubmitTenderOutStatusEnum.getMessage(submitTenderOutStatus));
            if(submitTenderInStatus.intValue() == SubmitTenderInStatusEnum.Not_Submitted_Qualifications_Check.getCode().intValue()){
                inviteTenderMemberResponse.setIsSubmitQualifications(true);
            }else{
                inviteTenderMemberResponse.setIsReSubmitQualifications(true);
            }
            return inviteTenderMemberResponse;
        }).collect(Collectors.toList());
        return Wrapper.success(new PageData<>(result.getTotalElements(), resultList));
    }

    /**
     * 投标-待新增投标列表
     */
    @RequestMapping(value = "/getAddSubmitTenderList", method = RequestMethod.POST)
    public Wrapper<PageData<InviteTenderMemberResponse>> getAddSubmitTenderList(@RequestBody SubmitTenderQueryRequest submitTenderQueryRequest) {
        UserLoginCacheDTO sysUser = this.getSysUser();

        List<Integer> submitTenderOutStatusList = new ArrayList<>();
        submitTenderOutStatusList.add(SubmitTenderOutStatusEnum.Not_Submit_Tender.getCode());
        submitTenderQueryRequest.setSubmitTenderOutStatusList(submitTenderOutStatusList);
        List<Integer> submitTenderInStatusList = new ArrayList<>();
        submitTenderInStatusList.add(SubmitTenderInStatusEnum.Not_Save_Submit_Tender.getCode());
        submitTenderInStatusList.add(SubmitTenderInStatusEnum.Not_Submitted_Check_Submit_Tender.getCode());
        submitTenderInStatusList.add(SubmitTenderInStatusEnum.Check_Submit_Tender_Not_Pass.getCode());
        submitTenderInStatusList.add(SubmitTenderInStatusEnum.Check_Submit_Tender_Not_Pass_2.getCode());
        submitTenderQueryRequest.setSubmitTenderInStatusList(submitTenderInStatusList);

        Page<InviteTenderMember> result = submitTenderService.getSubmitTenderList(sysUser, submitTenderQueryRequest);
        List<InviteTenderMember> inviteTenderMemberList = result.getContent();
        List<InviteTenderMemberResponse> resultList = inviteTenderMemberList.stream().map(inviteTenderMember -> {
            Integer submitTenderInStatus = inviteTenderMember.getSubmitTenderInStatus();
            Integer submitTenderOutStatus = inviteTenderMember.getSubmitTenderOutStatus();
            InviteTenderMemberResponse inviteTenderMemberResponse = BeanUtil.copyProperties(inviteTenderMember, InviteTenderMemberResponse.class);
            inviteTenderMemberResponse.setSubmitTenderInStatusValue(SubmitTenderInStatusEnum.getMessage(submitTenderInStatus));
            inviteTenderMemberResponse.setSubmitTenderOutStatusValue(SubmitTenderOutStatusEnum.getMessage(submitTenderOutStatus));
            if(submitTenderInStatus.intValue() == SubmitTenderInStatusEnum.Not_Submitted_Check_Submit_Tender.getCode().intValue()){
                inviteTenderMemberResponse.setIsSubmitCheck(true);
            }
            return inviteTenderMemberResponse;
        }).collect(Collectors.toList());
        return Wrapper.success(new PageData<>(result.getTotalElements(), resultList));
    }

    /**
     * 投标-待审核投标(一级)列表
     */
    @RequestMapping(value = "/getCheckSubmitTenderList", method = RequestMethod.POST)
    public Wrapper<PageData<InviteTenderMemberResponse>> getCheckSubmitTenderList(@RequestBody SubmitTenderQueryRequest submitTenderQueryRequest) {
        UserLoginCacheDTO sysUser = this.getSysUser();

        List<Integer> submitTenderOutStatusList = new ArrayList<>();
        submitTenderOutStatusList.add(SubmitTenderOutStatusEnum.Not_Submit_Tender.getCode());
        submitTenderQueryRequest.setSubmitTenderOutStatusList(submitTenderOutStatusList);
        List<Integer> submitTenderInStatusList = new ArrayList<>();
        submitTenderInStatusList.add(SubmitTenderInStatusEnum.Submitted_Check_Submit_Tender.getCode());
        submitTenderQueryRequest.setSubmitTenderInStatusList(submitTenderInStatusList);

        Page<InviteTenderMember> result = submitTenderService.getSubmitTenderList(sysUser, submitTenderQueryRequest);
        List<InviteTenderMember> inviteTenderMemberList = result.getContent();
        List<InviteTenderMemberResponse> resultList = inviteTenderMemberList.stream().map(inviteTenderMember -> {
            InviteTenderMemberResponse inviteTenderMemberResponse = BeanUtil.copyProperties(inviteTenderMember, InviteTenderMemberResponse.class);
            inviteTenderMemberResponse.setSubmitTenderInStatusValue(SubmitTenderInStatusEnum.getMessage(inviteTenderMember.getSubmitTenderInStatus()));
            inviteTenderMemberResponse.setSubmitTenderOutStatusValue(SubmitTenderOutStatusEnum.getMessage(inviteTenderMember.getSubmitTenderOutStatus()));
            return inviteTenderMemberResponse;
        }).collect(Collectors.toList());
        return Wrapper.success(new PageData<>(result.getTotalElements(), resultList));
    }

    /**
     * 投标-待审核投标(二级)列表
     */
    @RequestMapping(value = "/getCheckSubmitTenderList2", method = RequestMethod.POST)
    public Wrapper<PageData<InviteTenderMemberResponse>> getCheckSubmitTenderList2(@RequestBody SubmitTenderQueryRequest submitTenderQueryRequest) {
        UserLoginCacheDTO sysUser = this.getSysUser();

        List<Integer> submitTenderOutStatusList = new ArrayList<>();
        submitTenderOutStatusList.add(SubmitTenderOutStatusEnum.Not_Submit_Tender.getCode());
        submitTenderQueryRequest.setSubmitTenderOutStatusList(submitTenderOutStatusList);
        List<Integer> submitTenderInStatusList = new ArrayList<>();
        submitTenderInStatusList.add(SubmitTenderInStatusEnum.Submitted_Check_Submit_Tender_2.getCode());
        submitTenderQueryRequest.setSubmitTenderInStatusList(submitTenderInStatusList);

        Page<InviteTenderMember> result = submitTenderService.getSubmitTenderList(sysUser, submitTenderQueryRequest);
        List<InviteTenderMember> inviteTenderMemberList = result.getContent();
        List<InviteTenderMemberResponse> resultList = inviteTenderMemberList.stream().map(inviteTenderMember -> {
            InviteTenderMemberResponse inviteTenderMemberResponse = BeanUtil.copyProperties(inviteTenderMember, InviteTenderMemberResponse.class);
            inviteTenderMemberResponse.setSubmitTenderInStatusValue(SubmitTenderInStatusEnum.getMessage(inviteTenderMember.getSubmitTenderInStatus()));
            inviteTenderMemberResponse.setSubmitTenderOutStatusValue(SubmitTenderOutStatusEnum.getMessage(inviteTenderMember.getSubmitTenderOutStatus()));
            return inviteTenderMemberResponse;
        }).collect(Collectors.toList());
        return Wrapper.success(new PageData<>(result.getTotalElements(), resultList));
    }

    /**
     * 投标-待提交投标列表
     */
    @RequestMapping(value = "/getSubmittedSubmitTenderList", method = RequestMethod.POST)
    public Wrapper<PageData<InviteTenderMemberResponse>> getSubmittedSubmitTenderList(@RequestBody SubmitTenderQueryRequest submitTenderQueryRequest) {
        UserLoginCacheDTO sysUser = this.getSysUser();

        List<Integer> submitTenderOutStatusList = new ArrayList<>();
        submitTenderOutStatusList.add(SubmitTenderOutStatusEnum.Not_Submit_Tender.getCode());
        submitTenderQueryRequest.setSubmitTenderOutStatusList(submitTenderOutStatusList);
        List<Integer> submitTenderInStatusList = new ArrayList<>();
        submitTenderInStatusList.add(SubmitTenderInStatusEnum.Not_Submitted_Submit_Tender.getCode());
        submitTenderQueryRequest.setSubmitTenderInStatusList(submitTenderInStatusList);

        Page<InviteTenderMember> result = submitTenderService.getSubmitTenderList(sysUser, submitTenderQueryRequest);
        List<InviteTenderMember> inviteTenderMemberList = result.getContent();
        List<InviteTenderMemberResponse> resultList = inviteTenderMemberList.stream().map(inviteTenderMember -> {
            InviteTenderMemberResponse inviteTenderMemberResponse = BeanUtil.copyProperties(inviteTenderMember, InviteTenderMemberResponse.class);
            inviteTenderMemberResponse.setSubmitTenderInStatusValue(SubmitTenderInStatusEnum.getMessage(inviteTenderMember.getSubmitTenderInStatus()));
            inviteTenderMemberResponse.setSubmitTenderOutStatusValue(SubmitTenderOutStatusEnum.getMessage(inviteTenderMember.getSubmitTenderOutStatus()));
            return inviteTenderMemberResponse;
        }).collect(Collectors.toList());
        return Wrapper.success(new PageData<>(result.getTotalElements(), resultList));
    }

    /**
     * 查询投标信息
     * @param submitTenderId 投标id
     */
    @RequestMapping(value = "/getSubmitTender", method = RequestMethod.GET)
    public Wrapper<SubmitTenderInviteTenderMemberDetailResponse> getSubmitTender(@RequestParam Long submitTenderId) {
        UserLoginCacheDTO sysUser = this.getSysUser();
        InviteTenderMember inviteTenderMember = submitTenderService.getSubmitTenderMember(sysUser, submitTenderId);
        if(inviteTenderMember != null){
            SubmitTenderInviteTenderMemberDetailResponse inviteTenderMemberDetailResponse = BeanUtil.copyProperties(inviteTenderMember, SubmitTenderInviteTenderMemberDetailResponse.class);
            inviteTenderMemberDetailResponse.setSubmitTenderInStatusValue(SubmitTenderInStatusEnum.getMessage(inviteTenderMember.getSubmitTenderInStatus()));
            inviteTenderMemberDetailResponse.setSubmitTenderOutStatusValue(SubmitTenderOutStatusEnum.getMessage(inviteTenderMember.getSubmitTenderOutStatus()));

            //四舍五入，保留两位小数
            DecimalFormat decimalFormat = new DecimalFormat("#.00");
            //中标金额
            double winnerAmount = 0;
            double allWinnerAmount = 0;
            Boolean isWin = inviteTenderMember.getIsWin();
            if(isWin != null && isWin){
                SubmitTender submitTender = inviteTenderMember.getSubmitTender();
                if(submitTender != null){
                    List<SubmitTenderMateriel> submitTenderMaterielList = submitTender.getSubmitTenderMateriel();
                    if(submitTenderMaterielList != null && submitTenderMaterielList.size() > 0){
                        for (SubmitTenderMateriel submitTenderMateriel : submitTenderMaterielList) {
                            Boolean isAwardTender = submitTenderMateriel.getIsAwardTender();
                            if (isAwardTender != null && isAwardTender) {
                                Double price = submitTenderMateriel.getPrice();
                                Double awardTenderRatio = submitTenderMateriel.getAwardTenderRatio();
                                Double count = submitTenderMateriel.getInviteTenderMateriel().getCount();
                                winnerAmount = winnerAmount + (price * awardTenderRatio * count / 100);
                                allWinnerAmount = allWinnerAmount + (price * count);
                            }
                        }
                    }
                }
            }

            inviteTenderMemberDetailResponse.setWinnerAmount(Double.parseDouble(decimalFormat.format(winnerAmount)));
            inviteTenderMemberDetailResponse.setAllWinnerAmount(Double.parseDouble(decimalFormat.format(allWinnerAmount)));

            return Wrapper.success(inviteTenderMemberDetailResponse);
        }else{
            throw new BusinessException(ResponseCode.PURCHASE_INVITE_TENDER_NOT_EXIST);
        }
    }

    /**
     * 查询流程步骤
     */
    @RequestMapping(value = "/getSubmitTenderProcess", method = RequestMethod.GET)
    public Wrapper<ComplexTaskDefVO> getSubmitTenderProcess(@RequestParam Long submitTenderId) {
        UserLoginCacheDTO sysUser = this.getSysUser();
        ComplexTaskDefVO complexTaskDefVO = submitTenderService.getSubmitTenderProcess(sysUser, submitTenderId);
        return Wrapper.success(complexTaskDefVO);
    }

    /**
     * 投标报名
     * @param submitTenderRegisterRequest 参数
     */
    @RequestMapping(value = "/submitTenderRegister", method = RequestMethod.POST)
    public Wrapper<String> submitTenderRegister(@RequestBody @Valid SubmitTenderRegisterRequest submitTenderRegisterRequest){
        UserLoginCacheDTO sysUser = this.getSysUser();
        return Wrapper.success(submitTenderService.submitTenderRegister(sysUser, submitTenderRegisterRequest));
    }

    /**
     * 提交资格预审
     * @param submitQualificationsRequest 参数
     */
    @RequestMapping(value = "/submitQualifications", method = RequestMethod.POST)
    public Wrapper<String> submitQualifications(@RequestBody SubmitQualificationsRequest submitQualificationsRequest){
        UserLoginCacheDTO sysUser = this.getSysUser();
        return Wrapper.success(submitTenderService.submitQualifications(sysUser, submitQualificationsRequest));
    }

    /**
     * 新增/修改投标
     * @param submitTenderRequest 参数
     */
    @RequestMapping(value = "/saveSubmitTender", method = RequestMethod.POST)
    public Wrapper<String> saveSubmitTender(@RequestBody SubmitTenderRequest submitTenderRequest){
        UserLoginCacheDTO sysUser = this.getSysUser();
        return Wrapper.success(submitTenderService.saveSubmitTender(sysUser, submitTenderRequest));
    }

    /**
     *  提交审核投标
     * @param simpleIdListRequest 参数
     */
    @RequestMapping(value = "/submitCheckSubmitTender", method = RequestMethod.POST)
    public Wrapper<String> submitCheckSubmitTender(@RequestBody SimpleIdListRequest simpleIdListRequest){
        UserLoginCacheDTO sysUser = this.getSysUser();
        return Wrapper.success(submitTenderService.submitCheckSubmitTender(sysUser, simpleIdListRequest));
    }

    /**
     * 审核投标
     * @param checkRequest 参数
     */
    @RequestMapping(value = "/checkSubmitTender", method = RequestMethod.POST)
    public Wrapper<String> checkSubmitTender(@RequestBody CheckRequest checkRequest){
        UserLoginCacheDTO sysUser = this.getSysUser();
        return Wrapper.success(submitTenderService.checkSubmitTender(sysUser, checkRequest));
    }

    /**
     * 批量审核投标通过
     * @param simpleIdListRequest 参数
     */
    @RequestMapping(value = "/checkSubmitTenderBatch", method = RequestMethod.POST)
    public Wrapper<String> checkSubmitTenderBatch(@RequestBody SimpleIdListRequest simpleIdListRequest){
        UserLoginCacheDTO sysUser = this.getSysUser();
        return Wrapper.success(submitTenderService.checkSubmitTenderBatch(sysUser, simpleIdListRequest));
    }

    /**
     * 批量提交投标
     * @param simpleIdListRequest 参数
     */
    @RequestMapping(value = "/submitSubmitTenderBatch", method = RequestMethod.POST)
    public Wrapper<String> submitSubmitTenderBatch(@RequestBody SimpleIdListRequest simpleIdListRequest){
        UserLoginCacheDTO sysUser = this.getSysUser();
        return Wrapper.success(submitTenderService.submitSubmitTenderBatch(sysUser, simpleIdListRequest));
    }

}
